package com.googlecode.scup.parser;

import com.googlecode.scup.grammar.grammarspart.Symbol;

public class InputStream {
        private String stream;
        private Symbol result;
        private boolean flag;
        private int begin;

        public InputStream(String string) {
            stream = string;
            result = null;
            begin = 0;
            if (stream.length() != 0) flag = true;
            else flag = false;
        }

        public boolean hasNext() {
            return flag;
        }

        public Symbol getToken() {
            return result;
        }

        public void nextToken() {
            while (((stream.charAt(begin) == ' ')
                    || (stream.charAt(begin) == '\t')
                    || (stream.charAt(begin) == '\n'))){
                if (begin > stream.length()) {
                    flag = false;
                    return;
                }
                begin++;
            }
            int end = begin + 1;
            if (Character.isLetterOrDigit(stream.charAt(begin))) {
                while ((end < stream.length())
                        &&(stream.charAt(end) != ' ')
                        &&((stream.charAt(end) == '.')
                            || (Character.isLetterOrDigit(stream.charAt(end))))) {
                    end++;
                }
            }
            result = new Symbol(stream.substring(begin, end), true);
            begin = end;
            if (end >= stream.length()) {
                flag = false;
            }
        }
    }
